package com.fjec.market.mapper;

import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.fjec.market.entity.InfoFarmer;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.SelectProvider;

import java.time.LocalDateTime;
import java.util.List;
import java.util.Map;

/**
 * <p>
 * 004.果农表 Mapper 接口
 * </p>
 *
 * @author admin
 * @since 2020-09-07
 */
public interface InfoFarmerMapper extends BaseMapper<InfoFarmer> {
    List<InfoFarmer> getFarmerByMarkCode(@Param("markCode") Integer markCode, Page page);

    @SelectProvider(type = com.fjec.market.mapper.sqlbuilder.FarmerSqlBuilder.class, method = "getFarmersByFarmerIdsAndMarkCode")
    List<InfoFarmer> getFarmersByFarmerIdsAndMarkCode(@Param("markCode") int markCode, @Param("farmerIds") List<Long> farmerIds, Page page);

    @Select("select farmer.DepoStatus from info_farmer farmer where farmer.UserId=#{userId}")
    Map<String, Object> getFarmerDepoStatusByUserId(@Param("userId") Long userId);

    @Select("select business.DepoStatus from info_business business where business.UserId=#{userId}")
    Map<String, Object> getBusinessDepoStatusByUserId(@Param("userId") Long userId);

    List<InfoFarmer> getFarmerByShopNumAndMarkCode(@Param("markCode") int markCode, @Param("shopNum") Long shopNum);

    /**
     * 获取需要生成shopNum的果农列表
     *
     * @param limit
     * @param minutes
     * @return
     */
    List<Map<String, Object>> getFarmerForShopNumGen(@Param("limit") Integer limit,
                                                     @Param("minutes") Integer minutes);

    Map<String, Object> getFarmerWithMarkCodeByUserId(@Param("userId") Long userId);

    List<Map<String, Object>> getDepoInfoByConditions(@Param("searchBy") Integer searchBy,
                                                      @Param("title") String title,
                                                      @Param("busiType") Integer busiType,
                                                      @Param("markCode") Integer markCode,
                                                      @Param("depoStatus") Integer depoStatus,
                                                      @Param("timedBy") Integer timedBy,
                                                      @Param("startTime") LocalDateTime startTime,
                                                      @Param("endTime") LocalDateTime endTime,
                                                      @Param("page") Page page);

    /**
     * 统计果农数据
     *
     * @param startTime 统计开始时间
     * @return
     */
    List<Map<String, Object>> statFarmerData(@Param("startTime") LocalDateTime startTime,
                                             @Param("endTime") LocalDateTime endTime);

    Long getTotalDepoByConditions(Integer searchBy, String title, Integer busiType, Integer markCode, Integer depoStatus, Integer timedBy, String startTime, String endTime);

    /**
     * 临时定时更新店铺排序
     *
     * @return
     */
    Long tmpUpdateWeight(@Param("num") Integer num);
}
